package com.yc.rpc.grpc;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Level;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;

public class HelloWorldClient {

//    private final ManagedChannel channel; 
//    private final GreeterGrpc.GreeterBlockingStub blockingStub; 
//    private static final Logger logger = Logger.getLogger(HelloWorldClient.class.getName());
//
//    public HelloWorldClient(String host,int port){ 
//        channel = ManagedChannelBuilder.forAddress(host,port) 
//                .usePlaintext(true) 
//                .build();
//
//        blockingStub = GreeterGrpc.newBlockingStub(channel); 
//    }
//
//
//    public void shutdown() throws InterruptedException { 
//        channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); 
//    }
//
//    public  void greet(String name){ 
//        HelloRequest request = HelloRequest.newBuilder().setName(name).build(); 
//        HelloReply response; 
//        try{ 
//            response = blockingStub.sayHello(request); 
//        } catch (StatusRuntimeException e) 
//        { 
//            logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); 
//            return; 
//        } 
//        logger.info("Greeting: "+response.getMessage()); 
//    }
//
//    public static void main(String[] args) throws InterruptedException { 
//        HelloWorldClient client = new HelloWorldClient("127.0.0.1",50051); 
//        try{ 
//            String user = "world"; 
//            if (args.length > 0){ 
//                user = args[0]; 
//            } 
//            client.greet(user); 
//        }finally { 
//            client.shutdown(); 
//        } 
//    } 
}
